# coding=utf8
# 全世界最帅的帅哥
from flask_restful import Resource, reqparse
from flask import g
from comment.utils.decorators import login_required
from comment.modules.expected_return import ExpectedReturn
from .serializer import ExpectedReturnPaginateSerializer


class ExpectedReturnResource(Resource):
    method_decorators = [login_required]

    # 查看当前登录用户所有的预期收益的列表
    def get(self):
        rp = reqparse.RequestParser()
        rp.add_argument("curPage")  # 当前页
        rp.add_argument("perPage")  # 每页的数量
        args = rp.parse_args()
        cur_page = int(args.curPage)
        per_page = int(args.perPage)

        user_id = g.user_id

        expected_return_list = ExpectedReturn.query.filter(ExpectedReturn.userId == user_id)
        expected_return_list = expected_return_list.paginate(page=cur_page, per_page=per_page, error_out=False)
        data = ExpectedReturnPaginateSerializer(expected_return_list).to_dict()

        return {"msg": "查看预期收益成功", "data": data}

